"""
自定义异常

Author: wenbin
Create: 2024-08-17
"""

from .error import Error
from ..schema.response import ResponseCode


class CustomException(Exception):
    """
    自定义异常基类
    """
    code: int
    error_code: int
    message: str


class BusinessException(CustomException):
    """
    业务异常
    """
    code = 200

    def __init__(self, error: Error) -> None:
        self.error_code: int = error.value["code"]
        self.message: str = error.value["message"]
        super(BusinessException, self).__init__(self.message, None)


class ParameterException(CustomException):
    """
    参数异常
    """
    code = 400

    def __init__(self, message: str) -> None:
        self.error_code = ResponseCode.FAIL.value
        self.message = message
        super(ParameterException, self).__init__(self.message, None)
